﻿<%@ WebHandler Language="C#" Class="SIPO.Web.AjaxHandler.Loaddata.getAcceptanceDetail" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.Enum;
using SIPO.Web.Support;
using Newtonsoft.Json.Linq;

namespace SIPO.Web.AjaxHandler.Loaddata
{
    public class getAcceptanceDetail : SIPO.Web.BaseHandler
    {
        recAcceptanceDetailRepo acceptanceDetDal = new recAcceptanceDetailRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        recAcceptanceRepo acceptanceDal = new recAcceptanceRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        string MethodName = string.Empty;
        
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            if (context.Request.Params["method"] != null)
                MethodName = context.Request.Params["method"];
            
            if(MethodName.Equals("getAcceptanceId")){
                int acceptanceId = Convert.ToInt32(context.Request.Params["AcceptanceId"]);

                List<recAcceptanceDetail> acceptanceDetail = acceptanceDetDal.GetList();

                var result = acceptanceDetail.Where(x=>x.AcceptanceId==acceptanceId);

                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));

            }
            else if(MethodName.Equals("getDetailAcceptanceId"))
            {
                int acceptanceDetailId = Convert.ToInt32(context.Request.Params["AcceptanceDetailId"]);

                List<recAcceptanceDetail> acceptanceDetail = acceptanceDetDal.GetList();

                var result = acceptanceDetail.Where(x => x.AcceptanceDetailId==acceptanceDetailId);

                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));    
            }
            else if (MethodName.Equals("getdataversion"))
            {
                int Period = Convert.ToInt32(context.Request.Params["Period"]);

                List<recAcceptance> query = acceptanceDal.GetList().FindAll(x => x.AcceptancePeriod == Period);
                var transTypes = query.OrderBy(x => x.AcceptancePeriod).OrderByDescending(x => x.Versi);
                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(transTypes));    
            }
            
        }

        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}